﻿layui.use(["form", "layer", "jquery"], function () {
    var form = layui.form;
    var layer = layui.layer;
    var $ = layui.jquery;

    $(document).ready(function () {
        $("#viewMyAppointment").click(onViewMyAppointmentClick);
        $("#viewTeamAppointment").click(onViewTeamAppointmentClick);
        $("#viewTeamNotAppointment").click(onViewTeamNotAppointmentClick);
    });

    form.on("submit(filter-doAppointment)", function (data) {
        var type = $("input[name='appointmentType']:checked").val();
        var loadingIndex = layer.msg(addStyle("正在预约 ......"), { icon: 16, shade: 0.01, time: false });
        $.ajax("/Appointment/DoAppointment", {
            method: "POST",
            data: { appointmentType: type },
            complete: function (jqXHR, textStatus) {
                layer.close(loadingIndex);
            },
            success: function (data, textStatus, jqXHR) {
                if (data.Success == true) {
                    layer.msg(addStyle("预约成功！"), {
                        icon: 1, time: 1.5 * 1000
                    });
                } else {
                    layer.msg(addStyle("预约失败：" + data.Msg), { icon: 2, time: 3 * 1000, closeBtn: true });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg(addStyle("系统错误，请联系管理员！"), { icon: 2, time: 3 * 1000, closeBtn: true });
            }
        });

        return false;
    });

    function addStyle() {

    }

    function onViewMyAppointmentClick() {
        window.location = "/Appointment/MyAppointmentList";
    }

    function onViewTeamAppointmentClick() {
        window.location = "/Appointment/TeamAppointmentList";
    }

    function onViewTeamNotAppointmentClick() {
        window.location = "/Appointment/TeamNotAppointmentList";
    }

    function addStyle(str) {
        return '<span style="font-size: 16px;">' + str + '</span>';
    }
});